package com.ingrid.javi.activities.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ingrid.javi.R;
import com.ingrid.javi.R.id;
import com.ingrid.javi.R.layout;
import com.ingrid.javi.model.Movie;

public class MoviesAdapter extends BaseAdapter {

	private List<Movie> movies;
	private LayoutInflater inflater;

	public MoviesAdapter(List<Movie> movies, Context ctx) {
		this.movies = movies;
		this.inflater = LayoutInflater.from(ctx);
	}

	@Override
	public int getCount() {
		return this.movies.size();
	}

	@Override
	public Object getItem(int position) {
		return this.movies.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = this.inflater.inflate(R.layout.movie_item, parent,
					false);
		}
		TextView tvTitulo = (TextView) convertView.findViewById(R.id.tvTitulo);
		Movie movie = this.movies.get(position);
		tvTitulo.setText(movie.getTitulo());

		return convertView;
	}

}
